#ifndef __SUBSYSTEM_MUSKET_BLOCK_BEHAVIOR_H__
#define __SUBSYSTEM_MUSKET_BLOCK_BEHAVIOR_H__

#include "SubsystemBlockBehavior.hpp"
#include <unordered_map>

using namespace PocketSurvival::Engine;

namespace PocketSurvival
{
    struct ComponentMiner;
    class SubsystemProjectiles;
    class SubsystemTimeOfDay;

    // 枪的行为
    class SubsystemMusketBlockBehavior : public SubsystemBlockBehavior
    {
    protected:
        SubsystemProjectiles *m_projectiles;
        SubsystemTimeOfDay *m_timeOfDay;

        std::mutex m_mapMutex;
        std::unordered_map<ComponentMiner*, double> aimStartTimes;

    protected:
        void setAimTime(ComponentMiner* componentMiner, double time);
        void removeAimTime(ComponentMiner* componentMiner);
        double getAimTime(ComponentMiner* componentMiner);

    public:
        virtual const std::string& getName() const override;
        virtual void load(const nlohmann::json& json) override;

        virtual void update(float dt) override;
        virtual bool onAim(const Ray3 &aim, ComponentMiner *componentMiner, AimState state) override;
		virtual uint32_t getProcessInventoryItemCapacity(IInventory *inventory, uint32_t slotIndex, int32_t cellValue) override;
		virtual void processInventoryItem(IInventory *inventory, uint32_t slotIndex, int32_t cellValue, uint32_t count, uint32_t processCount, int32_t &outProcessedValue, uint32_t &outProcessedCount) override;
        virtual SubUpdateType getUpdateType() override;

    public:
        SubsystemMusketBlockBehavior();
    };
}

#endif